package mao.leetcode.others.leetcode414;

class Solution {
    public int thirdMax(int[] nums) {

        Long a = Long.MIN_VALUE;
        Long b=a,c=a;
        Long tmp = 0l;

        for(int i=0;i<nums.length;i++){
            tmp = (long)nums[i];
            if(tmp > a){
                c = b;
                b = a;
                a = tmp;
            }else if(tmp >b && tmp != a){
                c = b;
                b = tmp;
            }else if(tmp > c && tmp != b && tmp !=a ){
                c = tmp;
            }
        }
        if(c != Long.MIN_VALUE){
            return new Long(c).intValue();
        }else{
            return new Long(a).intValue();
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] a = {1,2,2,5,3,5};
        int i = solution.thirdMax(a);
    }
}
